/**
 * cube3d 实现立方体的拖拽效果
 * 
 * cube 立方体对象
 * rotateX rotateY 初始值
 * 
 * init 初始化
 * initData 初始化数据
 * drag 拖拽监听
 **/
var cube3d = {
    init: function (cube, rotateX, rotateY) {
        this.initData(cube, rotateX, rotateY);
        this.drag();
    },
    initData: function (cube, rotateX, rotateY) {
        this.cube = cube;
        this.rotateX = rotateX;
        this.rotateY = rotateY;
    },
    drag: function () {
        var that = this;
        /* 这里和之前的 3D旋转相册的是一样的 */
        document.onmousedown = function (event) {
            var oldX = event.clientX, oldY = event.clientY;
            this.onmousemove = function (event) {
                var newX = event.clientX, newY = event.clientY;
                var diffX = oldX - newX, diffY = oldY - newY;
                that.rotateX += diffY * 0.01, that.rotateY -= diffX * 0.01;
                that.cube.style.transform = "rotateX(" + that.rotateX + "deg) rotateY(" + that.rotateY + "deg)"
            }
            this.onmouseup = function () {
                this.onmousemove = null;    //清空鼠标移动事件
            }
        }
    }
}
